from django.contrib.auth.models import Group
from django.contrib.auth.models import Permission

from rest_framework.viewsets import ModelViewSet
from rest_framework.views import APIView
from rest_framework.response import Response

from apps.meiduo_admin.utils import PageNum
from apps.meiduo_admin.serializers.group import GroupSerializer
from apps.meiduo_admin.serializers.permission import PermissionSerializer


class GroupViewSet(ModelViewSet):
    # 获取组数据
    queryset = Group.objects.all().order_by('id')
    # 指定查询集
    serializer_class = GroupSerializer
    # 指定分页器
    pagination_class = PageNum


class GroupSimpleAPIView(APIView):

    def get(self, request):
        # 获取权限数据
        qs = Permission.objects.all()
        # 序列化对象
        serializer = PermissionSerializer(instance=qs, many=True)
        # 返回数据
        return Response(serializer.data)
